<template>
    <h3>登录页面</h3>
    <table border="1">
        <tr>
            <td>账号</td>
            <td>
                <input type="text" v-model="info.UName"/>
            </td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="info.Upwd"/>
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="登录" @click="LoginInfo">
            </td>
           
        </tr>
    </table>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios';

const info=ref({
    UName:"",
    Upwd:""
})

const LoginInfo=()=>{

    if(info.value.UName==""||info.value.Upwd==""){
        alert("账号或密码不能为空")
        return
    }

    axios.get("http://localhost:2134/api/User/Login",{
        params:{
           UName:info.value.UName,
            Upwd:info.value.Upwd
        }
    })
    .then((res)=>{
        console.log(res.data)
        if(res.data.length>0){
            alert("登录成功")
            location.href="/UserLogin"
        }
        else if(res.data.length==-1){
            alert("用户账号不能重复")
        }
        else{
            alert("密码错误")
        }
    })
}

</script>